package com.yulan.Sort;

import org.junit.Test;


/**
 *  75. 颜色分类
 *  将 0 1 2 数字
 */
public class LeetCode_75 {
    //三指针法
    public void sortColors(int[] nums) {
        int len = nums.length;
        if(len<2) return;
        int zero = 0;
        int two = len-1;

        int i = 0;
        while(i <= two){
            if(nums[i] == 0){
                swap(nums,i,zero);
                zero++;
                i++;
            }else if(nums[i] == 1){
                i++;
            }else{
                swap(nums,i,two);
                two--;
            }
        }
    }

    private void swap(int[] nums, int index1, int index2) {
        int temp = nums[index1];
        nums[index1] = nums[index2];
        nums[index2] = temp;
    }


    @Test
    public void test(){

    }
}
